/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "frm_control_TSelectBox.h"

using namespace frm;
using namespace control;

// TSelectBox /////////////////////////////////////////////////////////////////

//
TSelectBox::TSelectBox(control::TWindow &Window) : TLine(Window) 
{ 
  Width_ChildrenSum().Height_ChildrenMaxBase()
   .DirectChildren_Horz()
   .WAlignChildren_Begin().HAlignChildren_BeginBase();
}

//
void TSelectBox::TComponent_KeyboardChar(grf::TKeyboardChar &KeyboardChar)
{
  TWindow Window(*this); Window.ShowModal();
  TLine::TComponent_KeyboardChar(KeyboardChar);
}

//
TSelectBox::TWindow::TWindow(TSelectBox &SelectBox_) : SelectBox(SelectBox_)
{
  struct TStyle : public TPanel::TStyle
  {
    TStyle()
    {
      Filler.Set(filler::TColor(255,255,255));
      Cursor.Set(cursor::TCursorWin(IDC_ARROW));
    }
  };
  static TStyle Style;

  Client.SetStyle(Style);

  Client1 = new TPanel(Client.GetWindow()); Client.AddChildLast(Client1);
//  Client1->Events.Link(*this);
  Client1->SetStyle(Style)
   .Width_ChildrenMax().Height_ChildrenSum()
   .DirectChildren_Vert()
   .WAlignChildren_Begin().HAlignChildren_Begin();
}

//
void TSelectBox::TWindow::ShowModal()
{
  SelectBox.TSelectBox_BeforeShowBox(Client1);
  Client.CalcAllSize();

  control::TWindow &WindowSelectBox = SelectBox.GetWindow();
  TGeometryRect GRect; WindowSelectBox.CalcGeometryRect(&SelectBox,GRect);
  grf::TSize Size = Client1->GetSize();
    Size.Width = max(Size.Width,GRect.RThisVisible.Width);
  MoveWindowAroundClientRectTB(Size,WindowSelectBox,GRect.RThisVisible,false);
  
  //frm::TForm::ShowModal();
  grf::TWindow::ShowModal();
}

/*********************
//
void TSelectBox::TWindow::TEvents_KeyboardKey(TEvKeyboardKey &Param)
{
  if (Param.KeyboardKey.State == grf::TKeyboardKey::EState_Down)
  {
    if (Param.KeyboardKey.Key == VK_ESCAPE)
    {
      Hide();
    }
  }
  TEvents::TEvents_KeyboardKey(Param);
}
*****************/